import 'package:flutter/material.dart';
import 'package:gksz/experiment/experiment_details/jifen.dart';
import 'package:gksz/my/二级页面/shezhi.dart';
import 'package:gksz/my/二级页面/shuoming.dart';
import 'package:gksz/my/二级页面/lishi.dart';
import 'package:gksz/my/二级页面/dingyue.dart';
import 'package:gksz/my/二级页面/shoucang.dart';
import 'package:gksz/my/cv.dart';
import 'package:shared_preferences/shared_preferences.dart';
// import '../news/jiahao/tianjiahaoyou/details/erweima.dart';

class My extends StatefulWidget {
  My({Key key}) : super(key: key);

  _MyState createState() => _MyState();
}

class _MyState extends State<My> {
  

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Image.asset(
          'images/title.jpg',
          height: 25,
        ),
      ),
      body: ListView(
        children: ListTile.divideTiles(
          context: context,
          tiles: [
            MyCardp(),
          ListTile(
            leading: Icon(
              Icons.bookmark,
              color: Colors.red,
            ),
            title: Text('收藏'),
            trailing: Icon(Icons.keyboard_arrow_right),
            onTap: (){
              Navigator.of(context).push(MaterialPageRoute(
                          builder: (context) => Shoucang()));
            },
          ),
          // ListTile(
          //   leading: Icon(
          //     Icons.star,
          //     color: Colors.orange,
          //   ),
          //   title: Text('订阅'),
          //   trailing: Icon(Icons.keyboard_arrow_right),
          //   onTap: (){
          //     Navigator.of(context).push(MaterialPageRoute(
          //                 builder: (context) => Dingyue()));
          //   },
          // ),
          // ListTile(
          //   leading: Icon(
          //     Icons.access_time,
          //     color: Colors.green,
          //   ),
          //   title: Text('历史'),
          //   trailing: Icon(Icons.keyboard_arrow_right),
          //   onTap: (){
          //     Navigator.of(context).push(MaterialPageRoute(
          //                 builder: (context) => Lishi()));
          //   },
          // ),
          ListTile(
            leading: Icon(
              Icons.find_in_page,
              color: Colors.purple,
            ),
            title: Text('使用说明'),
            trailing: Icon(Icons.keyboard_arrow_right),
            onTap: (){
              Navigator.of(context).push(MaterialPageRoute(
                          builder: (context) => Shouming()));
            },
          ),
          ListTile(
            leading: Icon(
              Icons.settings,
              color: Color.fromRGBO(25, 75, 112, 1),
            ),
            title: Text('设置'),
            trailing: Icon(Icons.keyboard_arrow_right),
            onTap: (){
              Navigator.of(context).push(MaterialPageRoute(
                          builder: (context) => Shezhi()));
            }, 
          ),
          SizedBox(
            height: 40.0,
          ),
          ListTile(
                 title: Container(child: Text('退出',textAlign: TextAlign.center,),
                //  decoration: BoxDecoration(
                //    border: Border(
                //      bottom: BorderSide(width: 1)
                //    )
                //  ),
                ),                                  
                //  trailing: Icon(Icons.keyboard_arrow_right),
                //  contentPadding: EdgeInsets.symmetric(horizontal: 140.0),                
                 onTap: () async {
                   SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
                   //全部清空
                   sharedPreferences.clear();
                   Navigator.of(context).pushAndRemoveUntil(
                new MaterialPageRoute(builder: (context) => Loginpage()
                ),
                 (route) => route == null
                 );
                 }, 
               ),
          // ListTile(
          //   leading: Icon(
          //     Icons.settings,
          //     color: Color.fromRGBO(25, 75, 112, 1),
          //   ),
          //   title: Text('设置'),
          //   trailing: Icon(Icons.keyboard_arrow_right),
          //   onTap: (){
          //     Navigator.of(context).push(MaterialPageRoute(
          //                 builder: (context) => Shezhi()));
          //   },
          // ),
          ]          
        ).toList()
      ),
    );
  }
}

class MyCardp extends StatefulWidget {
  MyCardp({Key key}) : super(key: key);
// var name;
  _MyCardpState createState() => _MyCardpState();
}

class _MyCardpState extends State<MyCardp> {
  var name ;
  var point;
  getName() async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
      name = sharedPreferences.getString('username');
      point = sharedPreferences.getString('sumjifen');
      
      setState(() {});
  }
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getName();
  }

  int _shoucang = 1;
  @override
  Widget build(BuildContext context) {
    return Card(
      margin: EdgeInsets.all(10),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          ListTile(
            title: Row(
              children: <Widget>[
                Text('${name}'),
                SizedBox(
                  width: 15.0,
                ),
                // InkWell(
                //   child: Image.asset(
                //     'images/二维码.png',
                //     width: 25.0,
                //     height: 25.0,
                //   ),
                //   onTap: (){
                //     Navigator.of(context)
                //     .push(MaterialPageRoute(builder: (context) => ErWeiMa()));
                //   },
                // )
              ],
            ),
            // trailing: Container(
            //     margin: EdgeInsets.only(top: 10),
            //     width: 50.0,
            //     height: 50.0,
            //     decoration: ShapeDecoration(
            //         shape: CircleBorder(),
            //         image: DecorationImage(
            //             fit: BoxFit.cover,
            //             image: AssetImage(
            //               "images/head.jpg",
            //               )
            //             )
            //           )
            //         ),                        
                  ),
          // SizedBox(
          //   height: 20.0,
          // ),
          Row(
            children: <Widget>[
              SizedBox(
                 width: 6.8,
              ),
              Container(
                margin: EdgeInsets.fromLTRB(10, 0, 0, 0),
                width: 300,
                // child: Text('所属组织:' + '无',overflow: TextOverflow.ellipsis,),
              ),
            ],
          ),
          SizedBox(
            height: 20.0,
          ),
          Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Container(
                width: MediaQuery.of(context).size.width*0.85,
                height: 0.5,
                decoration: BoxDecoration(
                    border:
                        Border.all(color: Color.fromRGBO(220, 220, 220, 1))),
              )
            ],
          ),
          SizedBox(
            height: 8.0,
          ),
          Row(
            children: <Widget>[
              SizedBox(
                 width: 15.8,
              ),              
              InkWell(
                 child: Text('学习积分:'+'${point}',style: TextStyle(color: Colors.red,),),                
                 onTap: () {
                        Navigator.of(context).push(MaterialPageRoute(
                          builder: (context) => Jifen()));
                      },
              )
            ],
          ),          
          SizedBox(
            height: 15,
          ),
        ],
      ),
    );
  }
}
